﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace Form1
{
    class TimKiemData
    {
        sqlDataProvider sdp = new sqlDataProvider();
        public DataTable Thongke_an_uong()
        {
            SqlCommand cmd = new SqlCommand("Select MaHang, MatHang, SoLuong, DonViTinh, GiaNhap, GiaBan, Lai, MaPhieuOrder from ThongKeAnUong");
            sdp.Load(cmd);
            return sdp;
        }
        public void Update()
        {
            sdp.Update();
        }
        public DataTable timkiem(string txt_MaHang, string p1, string txt_MatHang, string p2, string txt_DonViTinh)
        {
            SqlCommand cmd = new SqlCommand();
            string sql = "Select MaHang, MatHang, DonViTinh from ThongKeAnUong where MaHang=@mahang ";
            cmd.Parameters.Add("mahang", SqlDbType.NVarChar, 50).Value = txt_MaHang;
            if (p1 != "NONE")
            {
                sql += p1 + " MatHang=@mathang ";
                cmd.Parameters.Add("mathang", SqlDbType.NVarChar, 10).Value = txt_MatHang;
            }
            if (p2 != "NONE")
            {
                sql += p2 + " DonViTinh=@dvt ";
                cmd.Parameters.Add("dvt", SqlDbType.Int).Value = Convert.ToInt32(txt_DonViTinh);
            }
            cmd.CommandText = sql;
            sdp.Load(cmd);
            return sdp;

        }
    }
}
